<script>
import LoginView from '@/components/LoginView.vue'
import Toast from '@/components/index/Toast.vue'
import Choice from '@/components/index/Choice.vue'
import { toastRef, choiceRef } from "@/common/index/utils/toast.js"
import { clientEvent } from '@/common/index/utils/ClientEvent'
import { KEY_BACK } from '@/common/index/config/Event'
import { choice } from '@/common/index/utils/toast.js'
/**
 * 登录页面
 */
export default {
  components: {
    LoginView,
    Toast,
    Choice
  },
  mounted() {
    toastRef.value = this.$refs.toastRef
    choiceRef.value = this.$refs.choiceRef
  },
  methods: {
    backpress() {
      choice("退出", "你要退出吗？", true, () => plus.runtime.quit())
    },
    mountEvent() {
      clientEvent.on(KEY_BACK, this.backpress, this)
    },
    unmountEvent() {
      clientEvent.off(KEY_BACK, this.backpress, this)
    }
  },
  onShow() {
    this.mountEvent()
  },
  onHide() {
    this.unmountEvent()
  },
  onUnload() {
    this.unmountEvent()
  }
}
</script>
<template>
  <view>
    <LoginView />
    <Toast ref="toastRef" />
    <Choice ref="choiceRef" />
  </view>
</template>

